package com.example.judge.domain;

import com.example.common.core.enums.CodeRunStatus;
import lombok.Data;

import java.util.List;

/**
 * @author 23050
 * @version 1.0
 * @description: 代码沙箱里面执行后需要返回的结果
 * @date 2025/5/2 19:47
 */
@Data
public class SandBoxExecuteResult {
    private CodeRunStatus runStatus;//代码执行状态
    private String exeMessage;//异常信息
    private List<String> outputList;//执行结果
    private Long useMemory;//占用内存 kb
    private Long useTime;//消耗时间 ms


    //执行失败 返回异常信息
    public static SandBoxExecuteResult fail(CodeRunStatus runStatus,
                                            String errorMsg) {
        SandBoxExecuteResult result = new SandBoxExecuteResult();
        result.setRunStatus(runStatus);
        result.setExeMessage(errorMsg);
        return result;
    }

    //执行失败   返回异常码和对应信息
    public static SandBoxExecuteResult fail(CodeRunStatus runStatus) {
        SandBoxExecuteResult result = new SandBoxExecuteResult();
        result.setRunStatus(runStatus);
        result.setExeMessage(runStatus.getMsg());
        return result;
    }

    //超时
    public static SandBoxExecuteResult fail(CodeRunStatus runStatus,
                                            List<String> outputList,
                                            Long useMemory,
                                            Long useTime) {
        SandBoxExecuteResult result = new SandBoxExecuteResult();
        result.setRunStatus(runStatus);
        result.setExeMessage(runStatus.getMsg());
        result.setOutputList(outputList);
        result.setUseMemory(useMemory);
        result.setUseTime(useTime);
        return result;
    }

    //成功
    public static SandBoxExecuteResult success(CodeRunStatus runStatus,
                                               List<String> outputList,
                                               Long useMemory,
                                               Long useTime) {
        SandBoxExecuteResult result = new SandBoxExecuteResult();
        result.setRunStatus(runStatus);
        result.setOutputList(outputList);
        result.setUseMemory(useMemory);
        result.setUseTime(useTime);
        return result;
    }




}
